package com.xiyuan.smartutils.filters;

import com.xiyuan.smartutils.Validates;

/**
 * 根据EndsWith进行过滤
 *
 * @version v1.0.0 @author lgz 2017-7-14 新建与整理
 */
public class FilterEndsWith implements Filter<String> {
    private final String endsWith;
    private final boolean ignoreCase;
    
    
    public FilterEndsWith(String endsWith) {
        this(endsWith, false);
    }
    
    public FilterEndsWith(String endsWith, boolean ignoreCase) {
        this.endsWith = endsWith;
        this.ignoreCase = true;
    }
    
    @Override
    public boolean accept(String src) {
        if (Validates.isEmpty(endsWith)) {return true;}
        if (src == null) {return false;}
        return ignoreCase ? src.toLowerCase().endsWith(endsWith) : src.endsWith(endsWith);
    }
}
